#include "preCmpH.h"
#include"UITimer.h"

BEGIN_NAMESPACE(ui_manager)
BEGIN_NAMESPACE(ui_events)

UITimer::UITimer()
{
	cycles.QuadPart = 0;
	interval = 100;
}
LARGE_INTEGER UITimer::cyclesPerSecond;
void UITimer::setInterval(int miliseconds)
{
	interval = miliseconds;
}
void UITimer::Start()
{
	QueryPerformanceFrequency( &cyclesPerSecond ) ;
}
void UITimer::Update(__int64 realTime)
{
	cycles.QuadPart += realTime;
	if(cycles.QuadPart > SecondsToCycles(interval / 1000.0f)){
		ticked = true;
		cycles.QuadPart = 0;
		return;
	}
	ticked = false;
}
__int64 UITimer::SecondsToCycles(float seconds)
{
	return (__int64)(seconds * cyclesPerSecond.QuadPart);
}
double UITimer::CyclesToSeconds(__int64 cycles_)
{
	return (double)cycles_ / cyclesPerSecond.QuadPart;
}
void UITimer::Reset()
{
	cycles.QuadPart = 0;
	ticked = false;
}

END_NAMESPACE
END_NAMESPACE